<template>
  <el-dialog :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false" :visible.sync="visible"
             @closed="close"
  >
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
             label-width="120px"
    >
      <el-form-item label="餐台名称前缀" prop="prefix">
        <el-input v-model="dataForm.prefix" placeholder="餐台名称前缀" class="input"></el-input>
      </el-form-item>
      <el-form-item label="餐台名称序号" prop="number">
        <el-input v-model="dataForm.number" placeholder="餐台名称序号" class="input"></el-input>
      </el-form-item>

      <el-form-item label="所属区域" prop="areaId">
        <el-select v-model="dataForm.areaId" placeholder="区域" class="input">
          <el-option v-for="item in areaList" :label="item.areaName" :key="item.areaId" :value="item.areaId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="标准用餐人数" prop="seatNum">
        <el-input v-model="dataForm.seatNum" placeholder="请输入1-99的整数" class="input"></el-input>
      </el-form-item>
      <!--		<el-form-item label="状态" prop="status">-->
      <!--		  <el-radio v-model="dataForm.status" label="1">空闲</el-radio>-->
      <!--		   <el-radio v-model="dataForm.status" label="2">就餐</el-radio>-->
      <!--		</el-form-item>-->
      <!--  <el-form-item label="点餐二维码" prop="qrCode">
      <el-input v-model="dataForm.qrCode" placeholder="点餐二维码"></el-input>
    </el-form-item> -->
      <el-form-item label="备注" prop="reamrk">
        <el-input v-model="dataForm.reamrk" placeholder="备注"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
			<el-button @click="visible = false">取消</el-button>
			<el-button type="primary" @click="dataFormSubmit()">确定</el-button>
		</span>
  </el-dialog>
</template>

<script>
import { listTableArea } from '@/api/table/tableArea'
import { getDiningTableById, saveOrUpdateDiningTable } from '@/api/table/diningTable'

export default {
  data() {
    return {
      visible: false,
      areaList: [],
      dataForm: {
        id: 0,
        prefix: '',
        number: '',
        sellerId: '',
        areaId: undefined,
        seatNum: '',
        status: '',
        qrCode: '',
        remark: ''
      },
      dataRule: {
        prefix: [{ required: true, message: '餐台名称前缀不能为空', trigger: 'blur' }],
        number: [{ required: true, message: '餐台名称序号不能为空', trigger: 'blur' }],
        sellerId: [{ required: true, message: '所属租户不能为空', trigger: 'blur' }],
        areaId: [{ required: true, message: '所属区域不能为空', trigger: 'blur' }],
        seatNum: [{ required: true, message: '座位数不能为空', trigger: 'blur' }],
        status: [{ required: true, message: '状态(1空闲2就餐)不能为空', trigger: 'blur' }],
        qrCode: [{ required: true, message: '点餐二维码不能为空', trigger: 'blur' }]
      }
    }
  },
  methods: {
    listArea() {
      listTableArea().then(response => {
        this.areaList = response.data
        this.dataForm.areaId = this.areaList[0].areaId
      })
    },
    close() {
      this.$emit('close')
    },
    init(id) {
      //餐厅类型
      this.listArea()
      this.dataForm.id = id || 0
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id) {
          getDiningTableById(this.dataForm.id).then(response => this.dataForm = response.data)
        }
      })
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs['dataForm'].validate(valid => {
        if (valid) {
          saveOrUpdateDiningTable(this.dataForm).then((response) => {
            this.$modal.msgSuccess(response.msg)
            this.visible = false
            this.$emit('refreshDataList')
          })
        }
      })
    }
  }
}
</script>
<style scoped>
.input {
  width: 200px;
}
</style>
